#pragma once
#include<vector>
using namespace std;

namespace knight
{
	template<class T>
	struct less
	{
		bool operator(const T& x1, const T& x2)
		{
			return x1 < x2;
		}
	};
	template<class T>
	struct greater
	{
		bool operator(const T& x1, const T& x2)
		{
			return x1 > x2;
		}
	};
	

	template<class T, class container = vector<int> ,class campare=less<T>>
	class priority_queue
	{
	public:
		void adjustup(int i)
		{
			campare com;
			int father = (i - 1) / 2;
			int child = i;
			while(child>0)
			{
				if (com( _con[father] , _con[child]) )
				{
					swap(_con[father], _con[child]);
					child = father;
					father = (child - 1) / 2;
				}
				else
				{
					break;
				}
			
			}
		}
		void adjustdown(int i)
		{
			campare com;

			int father = i;
			int child = 2 * i + 1;
			while (child<_con.size())
			{
				if (child + 1 < _con.size() && com(_con[child] , _con[child + 1]))
				{
					++child;
				}
				if (com(_con[father] ,_con[child]))
				{
					swap(_con[child], _con[father]);
					father = child;
					child = 2 * father + 1;

					
				}
				else
				{
					break;
				}
			}

		}

		void push(const T& val)
		{
			_con.push_back(val);
			adjustup(_con.size() - 1);
		}

	    void pop()
		{
			swap(_con[0], _con[_con.size() - 1]);
			_con.pop_back;
			adjustdown(0);
		}

		T& top()
		{
			return _con[0];

		}

		bool empty()
		{
			return _con.empty();
		}

		size_t size()
		{
			return  _con.size();
		}


	private:

		container _con;

	};




}